1 module unde.games.dizzy.omega.rotatable; 2 3 import derelict.opengl3.gl; 4 import std.conv; 5 import std.math; 6 import std.stdio; 7 import unde.games.object; 8 import unde.games.renderer; 9 import unde.global_state; 10 11 class Rotatable:StaticGameObject 12 { 13 bool hidden; 14 string model; 15 16 float def_x, def_y, def_z; 17 float def_degrees; 18 float degrees; 19 20 this(MainGameObject root, float[3] coords, float degrees, string model) 21 { 22 def_x = x = coords[0]; 23 def_y = y = coords[1]; 24 def_z = z = coords[2]; 25 26 models[model] = root.models[model]; 27 this.model = model; 28 def_degrees = this.degrees = degrees; 29 30 super(root); 31 } 32 33 override void draw(GlobalState gs) 34 { 35 if (!hidden && 36 abs(root.scrx-x) < 16.0 && 37 abs(root.scry-y) < 9.0) 38 { 39 glPushMatrix(); 40 glTranslatef(x, y, z); 41 glRotatef(degrees, 0.0, 1.0, 0.0); 42 recursive_render(gs, models[model]); 43 glPopMatrix(); 44 } 45 } 46 47 override bool tick(GlobalState gs) 48 { 49 return true; 50 } 51 52 override void load(string[string] s) 53 { 54 if ("rot-"~model~"-x" in s) 55 x = s["rot-"~model~"-x"].to!(float); 56 else 57 x = def_x; 58 59 if ("rot-"~model~"-y" in s) 60 y = s["rot-"~model~"-y"].to!(float); 61 else 62 y = def_y; 63 64 if ("rot-"~model~"-z" in s) 65 z = s["rot-"~model~"-z"].to!(float); 66 else 67 z = def_z; 68 69 if ("rot-"~model~"-degrees" in s) 70 degrees = s["rot-"~model~"-degrees"].to!(float); 71 else 72 degrees = def_degrees; 73 74 if ("rot-"~model in s) 75 { 76 hidden = (s["rot-"~model] == "hidden"); 77 } 78 else hidden = false; 79 } 80 81 override void save(ref string[string] s) 82 { 83 if (hidden) 84 s["rot-"~model] = "hidden"; 85 else 86 { 87 if (x != def_x) s["rot-"~model~"-x"] = x.to!(string); 88 if (y != def_y) s["rot-"~model~"-y"] = y.to!(string); 89 if (z != def_z) s["rot-"~model~"-z"] = z.to!(string); 90 if (degrees != def_degrees) s["rot-"~model~"-degrees"] = degrees.to!(string); 91 } 92 } 93 }